import { Component } from '@angular/core';
import { Track } from './track';

import { OnInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';

import { TrackService } from './track.service';

@Component({
  selector: 'my-tracks',
  templateUrl: './track.component.html'
})

export class TrackComponent implements OnInit {
  ngOnInit() {
    this.timerId = setInterval(() => {this.getTracks(); }, 5000);
  }
  timerId: any;

  track:  Track;

  constructor(
    private trackService: TrackService) {
  }

  getTracks() {
    this.trackService.getTrack().then(track => this.track = track);
    console.log(this.track);
  }

  ngOnDestroy() {
    clearInterval(this.timerId);
  }
}
